package com.example.demo.com.java8.stream;

import com.example.demo.com.java8.lambda.Apple;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * 1.创建stream
 * 2.中间操作
 * 3.终止操作
 * @author chengfei5
 * @date 2018/8/21
 */
public class TestStream1 {

    @Test
    public void test1(){
        //1.通过Collection系列集合提供的stream()或者parallelStream()
        List<String> stringList = new ArrayList<>();
        Stream<String> stream = stringList.stream();
        //2.通过Arrays中的静态方法stream()获取数组流
        Apple[] apples = new Apple[10];
        Stream<Apple> stream1 = Arrays.stream(apples);

        //3.通过Stream类中的静态方法of()
        Stream<String> stream2 = Stream.of("aa","bb","cc");
        //4.创建无限流
        //迭代(无限流)
        Stream.iterate(0,(x)->x+2).limit(10).forEach(System.out::println);
        //生成
        Stream.generate(()->Math.random()).limit(5).forEach(System.out::println);

    }
}
